
import java.io.File;
import java.util.TreeMap;

public class StyudentsTable 
{
    private Double[] P0_99 = new Double[1000];
    private Double[] P0_95 = new Double[1000];
    private Double[] P0_90 = new Double[1000];
    private Double[] P0_85 = new Double[1000];
    private Double[] P0_80 = new Double[1000];
    private Double[] P0_75 = new Double[1000];
    private Double[] P0_70 = new Double[1000];    
    private TreeMap reliability_columns_list = new TreeMap();
    StyudentsTable()
    {
        fillReliabilityColumnsList();
        createTable();
    }
    private void fillReliabilityColumnsList()
    {
        reliability_columns_list.put(0.99, P0_99);
        reliability_columns_list.put(0.95, P0_95);
        reliability_columns_list.put(0.90, P0_90);
        reliability_columns_list.put(0.85, P0_85);
        reliability_columns_list.put(0.80, P0_80);
        reliability_columns_list.put(0.75, P0_75);
        reliability_columns_list.put(0.70, P0_70);
    }  
    private void createTable()
    {
        WorkWithFile file_work = new WorkWithFile("/home/tatyana/Documents/Compressor/");
        File file = file_work.createFile("Styudents_Table");
        String text = new String(file_work.ReadFile(file));
        RegularExpression regex = new RegularExpression();
        String[] tokens = regex.SplitStyudentsTable(text);
        for(int i = 0, count = 0; i < tokens.length; i += 8, count++)
        {
            P0_99[count] =  Double.parseDouble(tokens[i + 1]);
            P0_95[count] =  Double.parseDouble(tokens[i + 2]);
            P0_90[count] =  Double.parseDouble(tokens[i + 3]);
            P0_85[count] =  Double.parseDouble(tokens[i + 4]);
            P0_80[count] =  Double.parseDouble(tokens[i + 5]);
            P0_75[count] =  Double.parseDouble(tokens[i + 6]);
            P0_70[count] =  Double.parseDouble(tokens[i + 7]);
        }
    }
    private Double[] getReliabilityColumn(double reliability)
    {
        return (Double[])reliability_columns_list.get(reliability);
    }  
    public double getStyudentsCoefficient(int degree_of_freedom, double reliability)
    {
        return getReliabilityColumn(reliability)[degree_of_freedom - 1];
    }   
}
